package com.ivr.cm.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
import org.springframework.jdbc.core.support.JdbcDaoSupport;

import com.ivr.cm.dao.ILimitUserDao;
import com.ivr.cm.util.BaseUtil;
import com.ivr.cm.vo.LimitUserVo;

public class LimitUserDaoImpl extends JdbcDaoSupport implements ILimitUserDao {
	private static Logger logger = Logger.getLogger(LimitUserDaoImpl.class);
	
	/**获得所有用户日月金额限制信息列表*/
	@SuppressWarnings("unchecked")
	@Override
	public List<LimitUserVo> getLimitUserList() {
		String sql = "select day_price, month_price from tb_ivr_limit_user where status = 1";
		logger.info(String.format("获得所有用户日月金额限制信息列表[%s]", sql));
		
		List<LimitUserVo> limitUserVoList = this.getJdbcTemplate().query(sql, rowMapper);
		if(limitUserVoList != null && limitUserVoList.size() > 0){
			return limitUserVoList;
		}
		return null;
	}
	/**获得自消费用户日月金额限制信息列表*/
	@SuppressWarnings("unchecked")
	@Override
	public List<LimitUserVo> getLimitUserConsumList(String sp_number) {
		String sql = "select day_price, month_price from tb_ivr_limit_user_consum where sp_number = ? and status = 1";
		Object[] params = new Object[]{sp_number};
		logger.info(String.format("获得所有用户日月金额限制信息列表[%s]", BaseUtil.logSQL(sql, params)));
		
		List<LimitUserVo> limitUserVoList = this.getJdbcTemplate().query(sql, params, rowMapper);
		if(limitUserVoList != null && limitUserVoList.size() > 0){
			return limitUserVoList;
		}
		return null;
	}
	private ParameterizedRowMapper<LimitUserVo> rowMapper = new ParameterizedRowMapper<LimitUserVo>() {
		@Override
		public LimitUserVo mapRow(ResultSet rs, int rowNum) throws SQLException {
			LimitUserVo limitUserVo = new LimitUserVo();
			limitUserVo.setDay_price(rs.getInt("day_price"));
			limitUserVo.setMonth_price(rs.getInt("month_price"));
			return limitUserVo;
		}
	};
	
}
